#include "lvgl/lvgl.h"
#include <stdio.h>
#include <windows.h>

LV_IMG_DECLARE(smart_watch_frame_black)
LV_IMG_DECLARE(smart_watch_frame_white)

LV_IMG_DECLARE(messages_on)
LV_IMG_DECLARE(messages_pushed)

LV_IMG_DECLARE(weather_on)
LV_IMG_DECLARE(weather_pushed)

LV_IMG_DECLARE(health_on)
LV_IMG_DECLARE(health_pushed)

LV_IMG_DECLARE(games_on)
LV_IMG_DECLARE(games_pushed)

LV_IMG_DECLARE(menu_icon_home)

LV_FONT_DECLARE(lv_font_montserrat_48)
LV_FONT_DECLARE(lv_font_montserrat_20)

#define WATCG_TOP_ICON_Y_START 3
#define WATCG_TOP_ICON_X_START 140

#define WATCG_TIME_X_START 70
#define WATCG_TIME_Y_START 120

#define WATCG_MENU_Y_START 250


/************************************************************************/
/* static variables                                                     */
/************************************************************************/
static void watch_welcome_create(void);
static void watch_top_icon_create(void);
static void watch_menu_create(void);

/**
 * action function
 */
static lv_res_t message_cb(lv_obj_t* obj, lv_event_t e);
static lv_res_t weather_cb(lv_obj_t* obj, lv_event_t e);
static lv_res_t health_cb(lv_obj_t* obj, lv_event_t e);
static lv_res_t games_cb(lv_obj_t* obj, lv_event_t e);
static lv_res_t home_cb(lv_obj_t* obj, lv_event_t e);


static lv_obj_t* watch_frame;
static lv_obj_t* watch_dial;

static lv_obj_t* message_cont;

void lv_app_create(void)
{
	watch_welcome_create();
}

/************************************************************************/
/* static functions                                                     */
/************************************************************************/
static void watch_welcome_create(void)
{
	SYSTEMTIME sys;
	GetLocalTime(&sys);


	watch_frame = lv_img_create(lv_scr_act(), NULL);
	lv_img_set_src(watch_frame, &smart_watch_frame_white);
	lv_obj_set_pos(watch_frame, 250, 0);

	watch_dial = lv_cont_create(watch_frame, NULL);
	lv_obj_set_size(watch_dial, 278, 312);
	lv_obj_set_style_local_radius(watch_dial, NULL, LV_STATE_DEFAULT, 20);
	lv_obj_set_pos(watch_dial, 20, 90);

	lv_obj_t* time = lv_label_create(watch_dial, NULL);
	lv_obj_set_style_local_text_font(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_montserrat_48);

	char time_string[6];
	sprintf_s(time_string, 6, "%2d:%2d", sys.wHour, sys.wMinute);
	lv_label_set_text(time, time_string);
	lv_obj_set_pos(time, WATCG_TIME_X_START, WATCG_TIME_Y_START);

	watch_top_icon_create();
	watch_menu_create();
}

static void watch_top_icon_create(void)
{
	static lv_style_t top_icon_style;


	lv_obj_t* wifi_icon = lv_label_create(watch_dial, NULL);
	lv_label_set_text(wifi_icon, LV_SYMBOL_WIFI);
	lv_obj_set_pos(
	        wifi_icon, WATCG_TOP_ICON_X_START, WATCG_TOP_ICON_Y_START);
	lv_obj_set_style_local_text_font(wifi_icon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_montserrat_20);

	lv_obj_t* bell_icon = lv_label_create(watch_dial, NULL);
	lv_label_set_text(bell_icon, LV_SYMBOL_BELL);
	lv_obj_set_pos(
	        bell_icon, WATCG_TOP_ICON_X_START + 30, WATCG_TOP_ICON_Y_START);
	lv_obj_set_style_local_text_font(bell_icon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_montserrat_20);



	lv_obj_t* bluetooth_icon = lv_label_create(watch_dial, NULL);
	lv_label_set_text(bluetooth_icon, LV_SYMBOL_BLUETOOTH);
	lv_obj_set_pos(bluetooth_icon,
	               WATCG_TOP_ICON_X_START + 60,
	               WATCG_TOP_ICON_Y_START);
	lv_obj_set_style_local_text_font(bluetooth_icon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_montserrat_20);

	lv_obj_t* battery_icon = lv_label_create(watch_dial, NULL);
	lv_label_set_text(battery_icon, LV_SYMBOL_BATTERY_FULL);
	lv_obj_set_pos(battery_icon,
	               WATCG_TOP_ICON_X_START + 90,
	               WATCG_TOP_ICON_Y_START);
	lv_obj_set_style_local_text_font(battery_icon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_montserrat_20);

}

static void watch_menu_create(void)
{
	static lv_style_t messages_style;

	lv_obj_t* messages = lv_imgbtn_create(watch_dial, NULL);
	lv_obj_set_pos(messages, 20, WATCG_MENU_Y_START);
	lv_imgbtn_set_src(messages, LV_BTN_STATE_RELEASED, &messages_on);
	lv_imgbtn_set_src(messages, LV_BTN_STATE_PRESSED, &messages_pushed);
	lv_obj_set_event_cb(messages, message_cb);


	lv_obj_t* weather = lv_imgbtn_create(watch_dial, NULL);
	lv_obj_set_pos(weather, 80, WATCG_MENU_Y_START);
	lv_imgbtn_set_src(weather, LV_BTN_STATE_RELEASED, &weather_on);
	lv_imgbtn_set_src(weather, LV_BTN_STATE_PRESSED, &weather_pushed);
	lv_obj_set_event_cb(weather, weather_cb);

	lv_obj_t* health = lv_imgbtn_create(watch_dial, NULL);
	lv_obj_set_pos(health, 140, WATCG_MENU_Y_START);
	lv_imgbtn_set_src(health, LV_BTN_STATE_RELEASED, &health_on);
	lv_imgbtn_set_src(health, LV_BTN_STATE_PRESSED, &health_pushed);
	lv_obj_set_event_cb(health, health_cb);

	lv_obj_t* games = lv_imgbtn_create(watch_dial, NULL);
	lv_obj_set_pos(games, 200, WATCG_MENU_Y_START);
	lv_imgbtn_set_src(games, LV_BTN_STATE_RELEASED, &games_on);
	lv_imgbtn_set_src(games, LV_BTN_STATE_PRESSED, &games_pushed);
	lv_obj_set_event_cb(games, games_cb);

}
static void message_cont_create(void)
{
	message_cont  = lv_page_create(watch_frame, NULL);
	lv_obj_set_size(message_cont, 278, 312);
	lv_obj_set_style_local_radius(message_cont, NULL, LV_STATE_DEFAULT, 20);
	lv_obj_set_pos(message_cont, 20, 90);

	lv_obj_t* label = lv_label_create(message_cont, NULL);
	lv_label_set_text(label, "messgae");
	lv_obj_set_pos(label, 20, 20);

	lv_obj_t* home = lv_imgbtn_create(message_cont, NULL);
	lv_imgbtn_set_src(home, LV_BTN_STATE_RELEASED ,&menu_icon_home);
	lv_imgbtn_set_src(home, LV_BTN_STATE_PRESSED,&menu_icon_home);
	lv_obj_set_event_cb(home, home_cb);
	lv_obj_set_pos(home, 200, 20);


	lv_obj_t* message_item1 = lv_msgbox_create(message_cont, NULL);
	lv_obj_set_size(message_item1, 225, 100);
	lv_obj_set_style_local_radius(message_item1, NULL, LV_STATE_DEFAULT, 20);
	lv_obj_set_pos(message_item1, 0, 50);
	lv_msgbox_set_text(message_item1, "Hi,My pohne number is 12598xxxxxx.\n");


	lv_obj_t* message_item2 = lv_msgbox_create(message_cont, NULL);
	lv_obj_set_size(message_item2, 225, 100);
	lv_obj_set_style_local_radius(message_item2, NULL, LV_STATE_DEFAULT, 20);
	lv_obj_set_pos(message_item2, 0, 150);
	lv_msgbox_set_text(message_item2, "shawn, invite you to barbecue tomorrow night.\n");

	lv_obj_t* message_item3 = lv_msgbox_create(message_cont, NULL);
	lv_obj_set_size(message_item3, 225, 100);
	lv_obj_set_style_local_radius(message_item3, NULL, LV_STATE_DEFAULT, 20);
	lv_obj_set_pos(message_item3, 0, 250);
	lv_msgbox_set_text(message_item3, "John has really raised the stakes in his  \n");
	
}

static lv_res_t message_cb(lv_obj_t* obj, lv_event_t e)
{
	if (e == LV_EVENT_RELEASED) {
		lv_obj_set_hidden(watch_dial, 1);
		message_cont_create();
	}
}

static lv_res_t weather_cb(lv_obj_t* obj, lv_event_t e)
{
	if (e == LV_EVENT_RELEASED) {
		lv_obj_set_hidden(watch_dial, 1);
	}
}

static lv_res_t health_cb(lv_obj_t* obj, lv_event_t e)
{
	if (e == LV_EVENT_RELEASED) {
		lv_obj_set_hidden(watch_dial, 1);
	}
}

static lv_res_t games_cb(lv_obj_t* obj, lv_event_t e)
{
	if (e == LV_EVENT_RELEASED) {
		lv_obj_set_hidden(watch_dial, 1);
	}
}

static lv_res_t home_cb(lv_obj_t* obj, lv_event_t e)
{
	if (e == LV_EVENT_RELEASED) {
		lv_obj_del(obj->parent->parent);
		//lv_obj_set_top(watch_dial, 1);
		
		lv_obj_set_hidden(watch_dial, 0);
	}
}